package com.xjscrm.console.service.customer.groupPull.impl;

import com.xjscrm.common.constant.ResponseMsg;
import com.xjscrm.common.exception.BusinessException;
import com.xjscrm.common.result.ResponseCode;
import com.xjscrm.console.param.groupSend.BatchGroupSendJobDto;

import com.xjscrm.console.param.groupSend.BatchUpdateSleepRuleDto;
import com.xjscrm.console.param.groupSend.UpdateSleepRuleDto;
import com.xjscrm.console.service.customer.groupPull.BatchGroupPullTaskService;
import com.xjscrm.console.service.customer.groupPull.GroupPullTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BatchGroupPullTaskServiceImpl implements BatchGroupPullTaskService {

    @Autowired
    private GroupPullTaskService groupPullTaskService;
    @Override
    public void batchUpdateSleepRule(BatchUpdateSleepRuleDto batchUpdateSleepRuleDto) {
        if (batchUpdateSleepRuleDto.getMerId() == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        if (batchUpdateSleepRuleDto.getUpdateSleepRuleDtoList() == null || batchUpdateSleepRuleDto.getUpdateSleepRuleDtoList().isEmpty()) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }

        for (UpdateSleepRuleDto updateSleepRuleDto : batchUpdateSleepRuleDto.getUpdateSleepRuleDtoList()) {
            try {
                updateSleepRuleDto.setMerId(batchUpdateSleepRuleDto.getMerId());
                groupPullTaskService.updatesleeprule(updateSleepRuleDto);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
